From 7a81d2bf551a6de1ce82c91c5d39ba865f1b9dbe Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 23 Mar 2005 12:55:54 +0000 Subject: [PATCH] Andrew Kirmse contributes "real" KML support, fixes Garmin routes. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@1100 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/garmin.c | 20 ++--- gpsbabel/kml.c | 224 +++++++++++++++++++++++++++++++++------------- 2 files changed, 169 insertions(+), 75 deletions(-) diff --git a/gpsbabel/garmin.c b/gpsbabel/garmin.c index 259709a71..3dc15938f 100644 --- a/gpsbabel/garmin.c +++ b/gpsbabel/garmin.c @@ -246,7 +246,7 @@ track_read(void) ntracks = GPS_Command_Get_Track(portname, &array); - if ( ntracks == 0 ) + if ( ntracks <= 0 ) return; for(i = 0; i < ntracks; i++) { @@ -306,15 +306,13 @@ route_read(void) int32 nroutepts; int i; GPS_PWay *array; + route_head *rte_head; nroutepts = GPS_Command_Get_Route(portname, &array); // fprintf(stderr, "Routes %d\n", (int) nroutepts); #if 1 for (i = 0; i < nroutepts; i++) { - route_head *rte_head; - waypoint * wpt_tmp; - if (array[i]->isrte) { char *csrc = NULL; /* What a horrible API has libjeeps for making this @@ -325,18 +323,16 @@ route_read(void) case 202: csrc = array[i]->rte_ident; break; default: break; } - rte_head = route_head_alloc(); - route_add_head(rte_head); - if (csrc) { - rte_head->rte_name = xstrdup(csrc); - } - ; - + rte_head = route_head_alloc(); + route_add_head(rte_head); + if (csrc) { + rte_head->rte_name = xstrdup(csrc); + } } else { if (array[i]->islink) { continue; } else { - wpt_tmp = xcalloc(sizeof (*wpt_tmp), 1); + waypoint *wpt_tmp = xcalloc(sizeof (*wpt_tmp), 1); wpt_tmp->latitude = array[i]->lat; wpt_tmp->longitude = array[i]->lon; wpt_tmp->shortname = array[i]->ident; diff --git a/gpsbabel/kml.c b/gpsbabel/kml.c index 0877936ce..606e5e29d 100644 --- a/gpsbabel/kml.c +++ b/gpsbabel/kml.c @@ -1,28 +1,22 @@ /* - Support for Keyhole "kml" format. + Support for Keyhole "kml" format. - STATUS: 03/15/2005 - This file is kind of sketchy and was based - on examining sample KML data files found on the net. I do now - have the full formal spec from Keyhole, but have not revisited - this file with that information yet. I'm checking it in becuase - there have been a couple of requests for KML support. RJL + Copyright (C) 2005 Robert Lipe, robertlipe@usa.net + Updates by Andrew Kirmse, akirmse at google.com + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - Copyright (C) 2005 Robert Lipe, robertlipe@usa.net + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ #include "defs.h" @@ -87,13 +81,13 @@ void wpt_e(const char *args, const char **unused) #if 0 void wpt_name_s(const char *args, const char **attrv) { - const char **avp = &attrv[0]; - while (*avp) { - if (0 == strcmp(avp[0], "id")) { - wpt_tmp->shortname = xstrdup(avp[1]); - } - avp+=2; - } + const char **avp = &attrv[0]; + while (*avp) { + if (0 == strcmp(avp[0], "id")) { + wpt_tmp->shortname = xstrdup(avp[1]); + } + avp+=2; + } } #endif @@ -145,60 +139,164 @@ kml_wr_deinit(void) fclose(ofd); } -static void -kml_waypt_pr(const waypoint *waypointp) +static void kml_output_timestamp(const waypoint *waypointp) +{ + if (waypointp->creation_time) { + fprintf(ofd, "\t \n"); + fprintf(ofd, "\t "); + xml_write_time(ofd, waypointp->creation_time, "timePosition"); + fprintf(ofd, "\t \n"); + } +} + +/* + * WAYPOINTS + */ + +static void kml_waypt_pr(const waypoint *waypointp) { - fputs(" \n", ofd); -// write_optional_xml_entity(ofd, "\t", "name", waypointp->shortname); + fprintf(ofd, "\t\n"); write_optional_xml_entity(ofd, "\t", "name", waypointp->description); + fprintf(ofd, "\t #waypoint\n"); - fprintf(ofd, "\t"); -#if 0 - if (waypointp->description) { - char *odesc = xml_entitize(waypointp->description); - fputs(odesc, ofd); - xfree(odesc); - } -#endif + // Description if (waypointp->url) { char * odesc = xml_entitize(waypointp->url); + fprintf(ofd, "\t "); fputs("\n", ofd); fputs(odesc, ofd); xfree(odesc); + fprintf(ofd, "\n\t\n"); } - fprintf(ofd, "\n\t\n"); -// write_optional_xml_entity(ofd, "\t", "description", waypointp->description); - fprintf(ofd, "\troot://styleMaps#default?iconId=0x400\n"); - fprintf(ofd, "\t\n"); + + // Location + fprintf(ofd, "\t \n"); fprintf(ofd, "\t\t%f,%f,%f\n", - waypointp->longitude, waypointp->latitude, waypointp->altitude == unknown_alt ? 0.0 : waypointp->altitude); - fprintf(ofd, "\t\n"); -#if 0 - fprintf(ofd, "", - waypointp->latitude, - waypointp->longitude); - fprintf(ofd, "\n"); + waypointp->longitude, waypointp->latitude, + waypointp->altitude == unknown_alt ? 0.0 : waypointp->altitude); + fprintf(ofd, "\t \n"); - if (waypointp->icon_descr) { - fprintf(ofd, "%s\n", deficon ? deficon : waypointp->icon_descr); - } - if (waypointp->url) { - tmp = xml_entitize(waypointp->url); - fprintf(ofd, "%s\n", - tmp); - xfree(tmp); - } -#endif - fprintf(ofd, " \n"); + // Timestamp + kml_output_timestamp(waypointp); + + fprintf(ofd, "\t\n"); } -void -kml_write(void) +/* + * TRACKPOINTS + */ + +static void kml_track_hdr(const route_head *header) +{ + fprintf(ofd, "\n"); + fprintf(ofd, " 1\n"); + write_optional_xml_entity(ofd, " ", "name", header->rte_name); + write_optional_xml_entity(ofd, " ", "desc", header->rte_desc); +} + +static void kml_track_disp(const waypoint *waypointp) +{ + fprintf(ofd, "\t\n"); + fprintf(ofd, "\t #track\n"); + fprintf(ofd, "\t \n"); + fprintf(ofd, "\t %f,%f,%f\n", + waypointp->longitude, waypointp->latitude, + waypointp->altitude == unknown_alt ? 0.0 : waypointp->altitude); + fprintf(ofd, "\t \n"); + + // Timestamp + kml_output_timestamp(waypointp); + + fprintf(ofd, "\t\n"); +} + +static void kml_track_tlr(const route_head *header) +{ + fprintf(ofd, "\n"); +} + +/* + * ROUTES + */ + +static void kml_route_hdr(const route_head *header) +{ + fprintf(ofd, "\n"); + fprintf(ofd, " 1\n"); + write_optional_xml_entity(ofd, " ", "name", header->rte_name); + write_optional_xml_entity(ofd, " ", "desc", header->rte_desc); +} + +static void kml_route_disp(const waypoint *waypointp) +{ + fprintf(ofd, "\t\n"); + fprintf(ofd, "\t #route\n"); + fprintf(ofd, "\t \n"); + fprintf(ofd, "\t %f,%f,%f\n", + waypointp->longitude, waypointp->latitude, + waypointp->altitude == unknown_alt ? 0.0 : waypointp->altitude); + fprintf(ofd, "\t \n"); + write_optional_xml_entity(ofd, "\t", "name", waypointp->description); + + // Timestamp + kml_output_timestamp(waypointp); + + fprintf(ofd, "\t\n"); +} + +static void kml_route_tlr(const route_head *header) +{ + fprintf(ofd, "\n"); +} + +static void kml_write_bitmap_style(const char *style, int bitmap, + int x, int y, int width, int height) +{ + fprintf(ofd, "\n"); +} + +void kml_write(void) { fprintf(ofd, "\n"); + fprintf(ofd, "\n"); + // TODO(akirmse): Put in device name, maybe time? + fprintf(ofd, "GPS device\n"); + fprintf(ofd, "1\n"); + + // Style settings for bitmaps + kml_write_bitmap_style("track", 4, 128, 0, 32, 32); + kml_write_bitmap_style("waypoint", 4, 160, 0, 32, 32); + kml_write_bitmap_style("route", 4, 160, 0, 32, 32); + fprintf(ofd, "\n"); + fprintf(ofd, "Waypoints\n"); + fprintf(ofd, "1\n"); + waypt_disp_all(kml_waypt_pr); + + fprintf(ofd, "\n"); + + // Output trackpoints + fprintf(ofd, "\n"); + fprintf(ofd, "Tracks\n"); + fprintf(ofd, "1\n"); + track_disp_all(kml_track_hdr, kml_track_tlr, kml_track_disp); fprintf(ofd, "\n"); + + // Output routes + fprintf(ofd, "\n"); + fprintf(ofd, "Routes\n"); + fprintf(ofd, "1\n"); + route_disp_all(kml_route_hdr, kml_route_tlr, kml_route_disp); + fprintf(ofd, "\n"); + + fprintf(ofd, "\n"); } ff_vecs_t kml_vecs = { -- 2.30.2